package com.pingbu.tijian.hospital.backapi.api;

import com.github.pagehelper.PageInfo;
import com.pingbu.common.bean.ResultBean;
import com.pingbu.common.utils.PbFileUtils;
import com.pingbu.tijian.hospital.backapi.bean.entity.Comment;
import com.pingbu.tijian.hospital.backapi.bean.entity.Revert;
import com.pingbu.tijian.hospital.backapi.bean.entity.StudentZuoye;
import com.pingbu.tijian.hospital.backapi.bean.entity.UserInfo;
import com.pingbu.tijian.hospital.backapi.bean.vo.FullTableStudentZuoye;
import com.pingbu.tijian.hospital.backapi.config.GlobalSet;
import com.pingbu.tijian.hospital.backapi.service.StudentService;
import com.pingbu.tijian.hospital.backapi.service.StudentZuoyeService;
import com.pingbu.tijian.hospital.backapi.service.UserInfoService;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/student_zuoye")
public class StudentZuoyeController {

    private static Logger logger = LoggerFactory.getLogger(StudentZuoyeController.class);

    @Autowired
    private UserInfoService userService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private StudentZuoyeService studentZuoyeService;
    @Autowired
    private GlobalSet globalSet;

    /**
     * 更新一个作业和学生的关系
     * 目的是更新数据表 t_student_zuoye
     * @return
     */
    @PostMapping(value = "/refresh_by_buzhi_zuoye_id")
    public ResultBean<Integer> refresh_by_buzhi_zuoye_id(@RequestBody StudentZuoye param ) {
        String stzyid = param.getBuzhi_zuoye_id();

        ResultBean<Integer> rb1 = studentZuoyeService.refreshByBuzhiZuoyeId(stzyid);
        return rb1;
    }

    /**
     * 简单登记页面的分页功能
     * @param param
     * @return
     */
    @PostMapping(value = "/simple_dengji_page")
    public ResultBean<PageInfo<StudentZuoye>> simple_dengji_page( @RequestBody StudentZuoye param) {
        ResultBean<PageInfo<StudentZuoye>> rb1 = studentZuoyeService.pageForSimpleDengji(param);
        return rb1;
    }

    /**
     * 全表显示页面的分页
     * @param param
     * @return
     */
    @PostMapping(value = "/full_table_page")
    public ResultBean<PageInfo<FullTableStudentZuoye>> full_table_page(@RequestBody FullTableStudentZuoye param ) {
        ResultBean<PageInfo<FullTableStudentZuoye>> rb1 = studentZuoyeService.pageForFullTable(param);
        return rb1;
    }

    @PostMapping(value = "/delete")
    public ResultBean<PageInfo<StudentZuoye>> delete(@RequestBody StudentZuoye param ) {
        ResultBean<PageInfo<StudentZuoye>> rb1 = studentZuoyeService.delete(param);
        return rb1;
    }

    @PostMapping(value = "/update")
    public ResultBean<PageInfo<StudentZuoye>> update(@RequestBody StudentZuoye param ) {
        ResultBean<PageInfo<StudentZuoye>> rb1 = studentZuoyeService.update(param);
        return rb1;
    }

    @PostMapping(value = "/zuoye_upload")
    public ResultBean<Integer> zuoye_upload(@RequestParam Map<String,String> param, MultipartFile uploadFile1) throws IOException {
        // ROOT/yyyy-MM/dd/文件名
        ResultBean<Integer> rb1 = studentZuoyeService.filePath(param, uploadFile1);
        return rb1;
    }

    @PostMapping(value = "/zuoye_download_path")
    public ResultBean<String> zuoye_download_path(@RequestBody StudentZuoye param ) throws IOException {
        // ROOT/yyyy-MM/dd/文件名
        ResultBean<String> rb1 = studentZuoyeService.download_path(param);
        return rb1;
    }



    @PostMapping(value = "/zuoye_get")
    public ResultBean<String> zuoye_get(@RequestBody StudentZuoye param){
        ResultBean<String> rb1 = studentZuoyeService.zuoye_get(param);
        return rb1;
    }

    @PostMapping(value = "/zuoye_view")
    public ResultBean<PageInfo<StudentZuoye>> zuoye_view(@RequestBody StudentZuoye param ) {
        ResultBean<PageInfo<StudentZuoye>> rb1 = studentZuoyeService.zuoyeView(param);
        return rb1;
    }

    @PostMapping(value = "/add_comment_msg")
    public ResultBean<String> send_msg(@RequestBody Comment param ) {
        ResultBean<String> rb1 = studentZuoyeService.commentMsg(param);
        return rb1;
    }

    @PostMapping(value = "/get_comment")
    public ResultBean<List<Comment>> getComment(@RequestBody Comment param ) {
        ResultBean<List<Comment>> rb1 = studentZuoyeService.getComment(param);
        return rb1;
    }

    @PostMapping(value = "/del_commentMsg")
    public ResultBean<Integer> delCommentMsg(@RequestBody Comment param ) {
        ResultBean<Integer> rb1 = studentZuoyeService.delCommentMsg(param);
        return rb1;
    }

    @PostMapping(value = "/add_revert_msg")
    public ResultBean<Integer> revert_msg(@RequestBody Revert param ) {
        ResultBean<Integer> rb1 = studentZuoyeService.revertMsg(param);
        return rb1;
    }

    @PostMapping(value = "/del_revertMsg")
    public ResultBean<Integer> delRevertMsg(@RequestBody Revert param ) {
        ResultBean<Integer> rb1 = studentZuoyeService.delRevertMsg(param);
        return rb1;
    }
}